<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div></div>
    <script>
        //自定义一个函数formatDate()，可以格式化时间信息。这个函数的参数可以有两种情况：
        //一种是符合标准格式的时间字符串，一种是Date对象的实例。返回的时间格式效果： 2021-10-06 15:15:09 星期几
        let div = document.querySelector('div');
        function formatDate(time){
            let now = new Date();
            let year = now.getFullYear();
            let month = now.getMonth()+1;
            let m = month<10?'0'+month:month;
            let dates = now.getDate();
            dates=dates<10?'0'+dates:dates;
            let day = now.getDay();
            let arr=['星期日','星期一','星期二','星期三','星期四','星期五','星期六'];
            let d=arr[day];
            let h = now.getHours();
            let min =now.getMinutes();
            min=min<10?'0'+min:min;
            let s = now.getSeconds();
            s=s<10?'0'+s:s;
            return div.innerHTML=year+'年'+m+'月'+dates+'日'+h+':'+min+':'+s+' '+d;
        }
        setInterval(formatDate,1000);
    </script>
</body>
</html>